﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Data;
using MES.DataGateway.SyncEntity;
using MES.DataGateway.Common;
using MES.DataGateway.SyncInterface;
using MES.DataGateway.StandardEntity;
using MES.DataGateway.OracleDAL;
using MES.DataGateway.SyncCommon;
using System.IO;
using System.Collections;
using System.Threading.Tasks;

namespace MES.DataGateway.StandardDataSync
{
    /// <summary>
    /// 工步信息保存，包括工步，工步检测项，工步工夹具，工步辅材，工步大小件，工步消耗件
    /// </summary>
    public class StepInfo : SyncInfterface
    {
        private AssistantClass m_Assistant = new AssistantClass();
        private ServiceEntity m_ServiceInfoEntity = null;
        private string m_ProjectID = "";
        private string m_LibID = "";
        private string m_DataFilePath = "";
        private string m_SyncType = "1";
        private OutInfoEntity m_OutParameterObject = null;
        private List<OutInfoEntity> m_OutParameterObjectList = new List<OutInfoEntity>();
        private string m_AccessoriesPath = "";
        private StandardDAL m_DAL;
        private ExecuteAPI exectAPI;
        string workFlowItemID = "";
        string workFlowRev = "";
        string workFlowProcessno = "";
        string ProductName = "";
        string ProductRevision = "";
        private string m_FileName = "";//add:Wangjh 20181218
        private string m_ProcessPlant = "";//工艺车间 YangSJ-11-10

        #region 属性
        public string AccessoriesPath
        {
            set { m_AccessoriesPath = value; }
        }

        public OutInfoEntity OutParameterObject
        {
            get { return m_OutParameterObject; }
        }

        public List<OutInfoEntity> OutParameterObjectList
        {
            get { return m_OutParameterObjectList; }
        }

        public ServiceEntity ServiceInfoEntity
        {
            get { return m_ServiceInfoEntity; }
            set { m_ServiceInfoEntity = value; }
        }

        public string ProjectID
        {
            get { return m_ProjectID; }
            set { m_ProjectID = value; }
        }

        public string LibID
        {
            get { return m_LibID; }
            set { m_LibID = value; }
        }

        public string DataFilePath
        {
            get { return m_DataFilePath; }
            set { m_DataFilePath = value; }
        }

        public string SyncType
        {
            get { return m_SyncType; }
            set { m_SyncType = value; }
        }
        public void ShowAttribute()
        {

        }
        #endregion

        public void Execute()
        {
            Log.SetConfig();//add:Wangjh 2017-9-15 
            m_DAL = new StandardDAL();
            DataSet ds = ReadXML();
            CreateStepInfo(ds);
        }

        private DataSet ReadXML()
        {
            XmlDocument myxml = new XmlDocument();
            myxml.Load(m_DataFilePath);
            m_FileName = Path.GetFileName(m_DataFilePath);
            DataTable stepinfodt = new DataTable("stepinfo");
            stepinfodt.Columns.Add("StepID");
            stepinfodt.Columns.Add("StepInfoName");//工步ID名称
            stepinfodt.Columns.Add("Revision");//版本
            stepinfodt.Columns.Add("StepType");//类型
            stepinfodt.Columns.Add("Description");//名称
            stepinfodt.Columns.Add("StepNo");//工步编号
            stepinfodt.Columns.Add("StepSeq");//工步顺序号
            stepinfodt.Columns.Add("Notes");//备注
            stepinfodt.Columns.Add("SpecialTool");//专用工夹具
            stepinfodt.Columns.Add("MeasureTool");//通用工夹具（量具）
            stepinfodt.Columns.Add("CheckPoint");//检测项
            stepinfodt.Columns.Add("Equip");//设备
            stepinfodt.Columns.Add("AuxMaterial");//辅材
            stepinfodt.Columns.Add("BigSmallPart");//大小零件
            stepinfodt.Columns.Add("MSpecName");//工序名称
            stepinfodt.Columns.Add("MSpecRevision");//工序版本
            stepinfodt.Columns.Add("CutTool");//刀具 add by longb 2023-08-08

            DataTable bomdt = new DataTable("bom");//消耗件
            bomdt.Columns.Add("StepInfoName");//工步ID名称
            bomdt.Columns.Add("StepInfoRevision");//工步版本
            bomdt.Columns.Add("MProductName");//消耗件图号
            bomdt.Columns.Add("MProductRevision");//消耗件版本
            bomdt.Columns.Add("MProductDesc");//消耗件名称
            bomdt.Columns.Add("MSpecName");//工序名称
            bomdt.Columns.Add("MSpecRevision");//工序版本
            bomdt.Columns.Add("MQtyRequired");//消耗数量
            XmlNode stu = myxml.SelectSingleNode("/Root/WorkFlow/MEProcesss/MEProcess/item_id");
            workFlowItemID = stu.InnerText.Trim();
            stu = myxml.SelectSingleNode("/Root/WorkFlow/MEProcesss/MEProcess/item_revision_id");
            workFlowRev = stu.InnerText.Trim();
            stu = myxml.SelectSingleNode("/Root/WorkFlow/MEProcesss/MEProcess/ly2process_no");
            workFlowProcessno = stu.InnerText.Trim();
            stu = myxml.SelectSingleNode("/Root/WorkFlow/MEProcesss/MEProcess/ly2plant");
            m_ProcessPlant = stu.InnerText;

            //取件号信息
            string[] productInfo = m_Assistant.GetProductName(m_DataFilePath);
            ProductName = productInfo[0];
            ProductRevision = productInfo[1];
            //

            stu = myxml.SelectSingleNode("/Root/WorkFlow/MEOPs");
            DataSet stepsDS = m_DAL.GetWorkflowStepsByItemID(workFlowItemID, workFlowProcessno, workFlowRev);
            if (stepsDS.Tables[0].Rows.Count == 0)
            {
                return null;
            }
            string stepName = "";
            foreach (XmlNode node in stu.ChildNodes)
            {
                if (node.Name != "MEOP")
                    continue;               

                //Modify by Yuxj20181015 针对装试的集件和去封，为了记录工时，需要在系统中创建工步（一次集件，一次去封，二次集件，二次去封）
                //if (OPnode == null)
                //    continue;
                stepName = string.Format("{0}-{1}",
                    node.SelectSingleNode("ly2meop_no").InnerText.Trim(),
                    node.SelectSingleNode("object_name").InnerText.Trim());
                DataRow[] drs = stepsDS.Tables[0].Select(string.Format("WORKFLOWSTEPNAME='{0}'", stepName));
                if (drs.Length == 0)
                    continue;

                //Modify by Yuxj20181015               
                XmlNode OPnode = node.SelectSingleNode("STEPs");
                if (OPnode == null)
                {
                    //增加判断，如果厂别为装试，并且工序中包含集件，构建DataSet,创建 工步（一次集件，一次去封，二次集件，二次去封）
                    stu = myxml.SelectSingleNode("/Root/WorkFlow/MEProcesss/MEProcess/ly2plant");
                    m_ProcessPlant = stu.InnerText;
                    if (m_ProcessPlant == "611") //装试分厂
                    {
                        string Seq = node.SelectSingleNode("ly2meop_no").InnerText.Trim();
                        string WfsName = node.SelectSingleNode("object_name").InnerText.Trim();
                        if (WfsName.IndexOf("集件") >= 0)
                        {
                           // continue;
                            FillStepInfo(stepinfodt, bomdt, drs[0], OPnode); //?此处为什么只取第0行
                        }
                        else
                            continue;

                    }
                    else
                        continue;
                }
                else
                {
                    if (OPnode.ChildNodes.Count > 0)
                    {
                        if (stepinfodt.Rows.Count > 0)
                        {
                            DataView dv = stepinfodt.DefaultView;
                            dv.RowFilter = "Description is not null ";
                            stepinfodt = dv.ToTable();
                        }
                        FillStepInfo(stepinfodt, bomdt, drs[0], OPnode);
                    }
                }
                
            }
            DataSet stepinfods = new DataSet();
            stepinfods.Tables.Add(stepinfodt);
            stepinfods.Tables.Add(bomdt);
            return stepinfods;
        }
        /// <summary>
        /// 填充工步信息
        /// </summary>
        /// <param name="stepdt"></param>
        /// <param name="bomdt"></param>
        /// <param name="stepdr"></param>
        /// <param name="opNode"></param>
        private void FillStepInfo(DataTable stepdt, DataTable bomdt, DataRow stepdr, XmlNode opNode)
        {
            string specname = stepdr["SPECNAME"].ToString();
            string specrev = stepdr["SPECREVISION"].ToString();
            //Modify by Yuxj20181015
            if (opNode == null)
            {
                string[] StepInfoArray = new string[4];
                StepInfoArray[0] = "一次集件";
                StepInfoArray[1] = "一次去封";
                StepInfoArray[2] = "二次集件";
                StepInfoArray[3] = "二次去封";
                string StepId = stepdr["WORKFLOWSTEPID"].ToString();
                for (int i = 0; i < StepInfoArray.Length; i++)
                {
                    if (m_DAL.StepInfoExists(StepId, StepInfoArray[i]))
                    {
                        //如果已经存在则退出
                        continue;
                    }
                    if (stepdr["WorkFlowStepName"].ToString().IndexOf("去封") >= 0)
                    {
                        if (i >= 2)
                            continue;

                    }
                    else if (stepdr["WorkFlowStepName"].ToString().IndexOf("集件") >= 0)
                    {
                        if (i < 2)
                            continue;

                    }

                    DataRow dr = stepdt.NewRow();
                    dr["StepID"] = stepdr["WORKFLOWSTEPID"].ToString();
                    dr["StepInfoName"] = StepInfoArray[i] + dr["StepID"];
                    dr["Revision"] = "01";
                    dr["StepType"] = string.Empty;
                    dr["Description"] = StepInfoArray[i];
                    dr["StepNo"] = "10";
                    dr["StepSeq"] = string.Empty;
                    dr["Notes"] = string.Empty;
                    dr["SpecialTool"] = string.Empty;
                    dr["MeasureTool"] = string.Empty;
                    dr["CheckPoint"] = string.Empty;                   
                    dr["Equip"] = string.Empty;
                    dr["AuxMaterial"] = string.Empty;
                    dr["BigSmallPart"] = string.Empty;
                    dr["MSpecName"] = string.Empty;
                    dr["MSpecRevision"] = specrev;
                    stepdt.Rows.Add(dr);
                }
            }
            else
            {
                int i_StepSeq = 1;
                foreach (XmlNode _node in opNode.ChildNodes)
                {
                    if (_node.Name != "STEP")
                        continue;
                    string StepInfoName = string.Format("{0}-{1}", stepdr["WORKFLOWSTEPID"].ToString(), _node.SelectSingleNode("item_id").InnerText.Trim());
                    if (string.IsNullOrEmpty(StepInfoName))
                        continue;
                    DataRow dr = stepdt.NewRow();
                    dr["StepID"] = stepdr["WORKFLOWSTEPID"].ToString();
                    dr["StepInfoName"] = StepInfoName;
                    dr["Revision"] = _node.SelectSingleNode("item_revision_id").InnerText.Trim();
                    if (_node.SelectSingleNode("ly2mestep_type") != null)
                    {
                        dr["StepType"] = _node.SelectSingleNode("ly2mestep_type").InnerText.Trim();
                    }
                    dr["Description"] = _node.SelectSingleNode("object_name").InnerText.Trim();

                    //yuxj20220825
                    //dr["StepNo"] = _node.SelectSingleNode("ly2meop_no").InnerText.Trim();
                    //dr["StepSeq"] = _node.SelectSingleNode("ly2MEStep_no").InnerText.Trim();
                    if (_node.SelectSingleNode("ly2MEStep_no") != null)
                    {
                        dr["StepNo"] = _node.SelectSingleNode("ly2MEStep_no").InnerText.Trim();
                    }

                    dr["StepSeq"] = i_StepSeq;
                    i_StepSeq++;

                    if (_node.SelectSingleNode("stepContent") != null)
                    {
                        dr["Notes"] = _node.SelectSingleNode("stepContent").InnerText.Trim();//ly2remark modify by longb 2022-09-13
                    }
                    if (_node.SelectSingleNode("ly2SpecTool") != null)
                    {
                        dr["SpecialTool"] = _node.SelectSingleNode("ly2SpecTool").InnerText.Trim();
                    }
                    //add by longb 2023-08-08 夹模具新取节点数据 ly2SpecTool为空时
                    if (_node.SelectSingleNode("SpeToolTools") != null)
                    {
                        string Mtools = string.Empty;
                        foreach (XmlNode mtool in _node.SelectSingleNode("SpeToolTools").ChildNodes)
                        {
                            string Mtool = string.Empty;
                            Mtool += mtool.SelectSingleNode("code").InnerText + "$";//夹模具编码
                            Mtool += mtool.SelectSingleNode("drawingNo").InnerText + "$";//图号
                            Mtool += mtool.SelectSingleNode("code").InnerText + "$";//夹模具名称
                            Mtool += "$";//
                            Mtool += mtool.SelectSingleNode("quallity").InnerText + "$";//数量
                            Mtool += "";//备注
                            Mtools += Mtool + ",";
                        }
                        if (string.IsNullOrWhiteSpace(dr["SpecialTool"].ToString()))
                        {
                            dr["SpecialTool"] = Mtools.TrimEnd(',');
                        }
                    }
                    if (_node.SelectSingleNode("ly2StandTool") != null)
                    {
                        dr["MeasureTool"] = _node.SelectSingleNode("ly2StandTool").InnerText.Trim();
                    }
                    //add by longb 2023-08-08 量具新取节点数据 ly2StandTool为空时
                    if (_node.SelectSingleNode("MeasureTools") != null)
                    {
                        string Mtools = string.Empty;
                        foreach (XmlNode mtool in _node.SelectSingleNode("MeasureTools").ChildNodes)
                        {
                            string Mtool = string.Empty;
                            Mtool += mtool.SelectSingleNode("code").InnerText + "$";//量具编码
                            Mtool += mtool.SelectSingleNode("name").InnerText + "$";//量具名称
                            Mtool += mtool.SelectSingleNode("specNo").InnerText + "$";//规格--
                            Mtool += mtool.SelectSingleNode("range").InnerText + "$";//量程
                            Mtool += mtool.SelectSingleNode("precision").InnerText + "$";//精度
                            Mtool += mtool.SelectSingleNode("standardNo").InnerText + "$";//标准号
                            Mtool += mtool.SelectSingleNode("quallity").InnerText + "$";//数量
                            Mtool += "";//备注
                            Mtools += Mtool + ",";
                        }
                        if (string.IsNullOrWhiteSpace(dr["MeasureTool"].ToString()))
                        {
                            dr["MeasureTool"] = Mtools.TrimEnd(',');
                        }
                    }
                    //add by longb 2023-08-09 刀具新取节点数据
                    if (_node.SelectSingleNode("CutTools") != null)
                    {
                        string Ctools = string.Empty;
                        foreach (XmlNode ctool in _node.SelectSingleNode("CutTools").ChildNodes)
                        {
                            string Ctool = string.Empty;
                            Ctool += ctool.SelectSingleNode("code").InnerText + "$";//刀具编码
                            Ctool += ctool.SelectSingleNode("name").InnerText + "$";//刀具名称
                            Ctool += ctool.SelectSingleNode("specNo").InnerText + "$";//规格
                            Ctool += ctool.SelectSingleNode("drawingNo").InnerText + "$";//图号
                            Ctool += "$";//备注
                            Ctool += ctool.SelectSingleNode("standardNo").InnerText + "$";//标准号
                            Ctool += ctool.SelectSingleNode("quallity").InnerText;//数量
                            Ctools += Ctool + ",";
                        }
                        if (string.IsNullOrWhiteSpace(dr["CutTool"].ToString()))
                        {
                            dr["CutTool"] = Ctools.TrimEnd(',');
                        }
                    }
                    if (_node.SelectSingleNode("ly2Inspection") != null)
                    {
                        //旧的方式
                        dr["CheckPoint"] = _node.SelectSingleNode("ly2Inspection").InnerText.Trim();
                    }
                    //else if (_node.SelectSingleNode("Checks") != null)
                    //{
                    //    //新方式 单独类处理
                    //    XmlNode nodeCheck = _node.SelectSingleNode("Checks");
                    //    if (nodeCheck.ChildNodes.Count > 0)
                    //    {
                            
                    //    }
 
                    //}


                    if (_node.SelectSingleNode("ly2Equip") != null)
                    {
                        dr["Equip"] = _node.SelectSingleNode("ly2Equip").InnerText.Trim();
                    }
                    if (_node.SelectSingleNode("ly2Material") != null)
                    {
                        dr["AuxMaterial"] = _node.SelectSingleNode("ly2Material").InnerText.Trim();
                    }
                    if (_node.SelectSingleNode("ly2BigSmallPart") != null)
                    {
                        dr["BigSmallPart"] = _node.SelectSingleNode("ly2BigSmallPart").InnerText.Trim();
                    }
                    //add by longb 2023-07-13 辅材新取节点数据 ly2Material为空时
                    if (_node.SelectSingleNode("Materials") != null) 
                    {
                        string Materials = string.Empty;
                        foreach (XmlNode material in _node.SelectSingleNode("Materials").ChildNodes)
                        {
                            string Material = string.Empty;
                            Material += material.SelectSingleNode("code").InnerText + "$";
                            Material += material.SelectSingleNode("name").InnerText + "$";
                            Material += material.SelectSingleNode("specNo").InnerText + "$";
                            Material += material.SelectSingleNode("mark").InnerText + "$";
                            Material += material.SelectSingleNode("standard").InnerText + "$";
                            Material += material.SelectSingleNode("quallity").InnerText + "$";
                            Material += material.SelectSingleNode("remark").InnerText;
                            Materials += Material + ",";
                        }
                        if (string.IsNullOrWhiteSpace(dr["AuxMaterial"].ToString())) 
                        {
                            dr["AuxMaterial"] = Materials.TrimEnd(',');
                        }
                    }
                    dr["MSpecName"] = specname;
                    dr["MSpecRevision"] = specrev;
                    stepdt.Rows.Add(dr);
                    XmlNode OPnode = _node.SelectSingleNode("MEConsumeds");
                    if (OPnode.ChildNodes.Count > 0)
                    {
                        FillBomInfo(bomdt, dr["StepInfoName"].ToString(), dr["Revision"].ToString(), specname, specrev, OPnode);
                    }
                }
            }
        }
              

        /// <summary>
        /// 工步消耗件
        /// </summary>
        /// <param name="bomdt"></param>
        /// <param name="stepinfoname"></param>
        /// <param name="stepinforevision"></param>
        /// <param name="specname"></param>
        /// <param name="specrev"></param>
        /// <param name="opNode"></param>
        private void FillBomInfo(DataTable bomdt, string stepinfoname, string stepinforevision, string specname, string specrev, XmlNode opNode)
        {
            foreach (XmlNode _node in opNode.ChildNodes)
            {
                if (_node.Name != "MEConsumedele")
                    continue;
                string MProductName = _node.SelectSingleNode("item_id").InnerText.Trim();
                if (string.IsNullOrEmpty(MProductName))
                    continue;
                DataRow dr = bomdt.NewRow();
                dr["StepInfoName"] = stepinfoname;
                dr["StepInfoRevision"] = stepinforevision;
                dr["MProductName"] = MProductName;
                dr["MProductRevision"] = _node.SelectSingleNode("item_revision_id").InnerText.Trim();
                dr["MProductDesc"] = _node.SelectSingleNode("object_name").InnerText.Trim();
                dr["MSpecName"] = specname;
                dr["MSpecRevision"] = specrev;
                dr["MQtyRequired"] = _node.SelectSingleNode("bl_quantity").InnerText.Trim();
                bomdt.Rows.Add(dr);

            }
        }
        /// <summary>
        /// 保存工步
        /// </summary>
        /// <param name="stepinfods"></param>
        private void CreateStepInfo(DataSet stepinfods)
        {
            if (stepinfods == null)
                return;
            if (stepinfods.Tables.Count == 0)
                return;
            if (!stepinfods.Tables.Contains("stepinfo"))
                return;
            if (stepinfods.Tables["stepinfo"].Rows.Count == 0)
                return;
            exectAPI = new ExecuteAPI();
            string cdoName = "StepInfo";
            DataTable BigSmallPartDT = stepinfods.Tables["bom"].Clone();
            BigSmallPartDT.Columns.Add("Qty2");
            BigSmallPartDT.Columns.Add("BigSmallPart");
            BigSmallPartDT.Columns.Add("Notes");
            //foreach (DataRow dr in stepinfods.Tables["stepinfo"].Rows)
            System.Threading.Tasks.Parallel.ForEach(stepinfods.Tables["stepinfo"].Select(), new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount }, dr =>
            {
                SyncParameterEntity stepinfoentity = FillStepInfoCDO(dr);
                string StepInfoName = dr["StepInfoName"].ToString();
                string stepinfoRev = dr["Revision"].ToString();
                DataTable StepInfotmpdt = m_DAL.GetRDOByAllVersion("StepInfo", "StepInfoName", StepInfoName);

                OutInfoEntity infoEntity = new OutInfoEntity();
                if (StepInfotmpdt.Rows.Count > 0)
                {
                    string strOldVersion = StepInfotmpdt.Select("StepInfoID=Revofrcdid")[0]["Revision"].ToString();
                    if (StepInfotmpdt.Select(string.Format("StepInfoName='{0}' and Revision='{1}'", StepInfoName, stepinfoRev)).Length == 0)
                    {
                        if (strOldVersion.Trim() == "")
                        {
                            Log.WriteOrcale("PDMTOMES_StepInfo" + "@^" + StepInfoName + "未能找到默认版本，无法创建！" + "@^" + m_FileName + "@^" + Convert.ToString(Guid.NewGuid()) + "@^" + ProductName + ":" + ProductRevision);//add:Wangjh 写入数据库          
                            return;
                            //continue;
                        }
                        else
                        {
                            exectAPI.CreateRDOEntityRevision(cdoName, StepInfoName, strOldVersion, stepinfoentity, ref infoEntity);
                        }
                    }
                    else
                    {
                        Log.WriteOrcale("PDMTOMES_StepInfo" + "@^" + StepInfoName + "." + stepinfoRev + "已经存在！" + "@^" + m_FileName + "@^" + Convert.ToString(Guid.NewGuid()) + "@^" + ProductName + ":" + ProductRevision);//add:Wangjh 写入数据库          
                        //exectAPI.UpdateRDOEntity(cdoName, StepInfoName, strOldVersion, stepinfoentity, ref infoEntity);
                    }
                }
                else
                {
                    exectAPI.CreateRDOEntity(cdoName, stepinfoentity, ref infoEntity);
                }
                m_OutParameterObjectList.Add(infoEntity);
                if (infoEntity.OutFlag == 1)//add:Wangjh 2017-9-15
                {
                    Log.WriteOrcale("PDMTOMES_StepInfo" + "@^" + StepInfoName + "StepInfo创建成功" + "@^" + m_FileName + "@^" + Convert.ToString(Guid.NewGuid()) + "@^" + ProductName + ":" + ProductRevision);//add:Wangjh 写入数据库          
                }
                else if (infoEntity.OutFlag == 2)
                {
                    Log.WriteOrcale("PDMTOMES_StepInfo" + "@^" + "StepInfo创建失败:" + infoEntity.StrInfo + "@^" + m_FileName + "@^" + Convert.ToString(Guid.NewGuid()) + "@^" + ProductName + ":" + ProductRevision);//add:Wangjh 写入数据库          
                }

                DataTable stepinfodt = m_DAL.GetRDOTable("StepInfo", "StepInfoName", dr["StepInfoName"].ToString(), "Revision", dr["Revision"].ToString());
                if (stepinfodt.Rows.Count > 0)
                {
                    string stepinfoid = stepinfodt.Rows[0]["StepInfoID"].ToString();
                    try
                    {
                        CreateRelationInfo(stepinfoid, dr);
                    }
                    catch (Exception ex)
                    {
                        Log.WriteOrcale("PDMTOMES_StepInfo" + "@^" + "StepInfo创建失败:" + ex.Message + "@^" + m_FileName + "@^" + Convert.ToString(Guid.NewGuid()) + "@^" + ProductName + ":" + ProductRevision);//add:Wangjh 写入数据库          
                    }
                    FillBigSmallPart(dr, BigSmallPartDT);
                }

            });
            CreateBom(stepinfods.Tables["bom"], false);//消耗件
            CreateBom(BigSmallPartDT, true);//大小件目录
            LoadUrlsInfo(stepinfods.Tables["stepinfo"]);//pdm地址
            inheritLastWorkflowSomeInfo("WF-"+workFlowProcessno,workFlowRev);
        }

        private SyncParameterEntity FillStepInfoCDO(DataRow dr)
        {
            SyncParameterEntity inputParaEntity = new SyncParameterEntity();
            #region 属性赋值
            DataEntity entity = new DataEntity();
            entity.FieldName = "Name";
            entity.FieldType = "dataField";
            entity.FieldValue = dr["StepInfoName"].ToString();
            inputParaEntity.DataList.Add(entity);

            entity = new DataEntity();
            entity.FieldName = "Revision";
            entity.FieldType = "dataField";
            entity.FieldValue = dr["Revision"].ToString();
            inputParaEntity.DataList.Add(entity);

            entity = new DataEntity();
            entity.FieldName = "Description";
            entity.FieldType = "dataField";
            entity.FieldValue = dr["Description"].ToString();
            inputParaEntity.DataList.Add(entity);

            entity = new DataEntity();
            entity.FieldName = "Notes";
            entity.FieldType = "dataField";
            entity.FieldValue = dr["Notes"].ToString();
            inputParaEntity.DataList.Add(entity);

            entity = new DataEntity();
            entity.FieldName = "StepNo";
            entity.FieldType = "dataField";
            entity.FieldValue = dr["StepNo"].ToString();
            inputParaEntity.DataList.Add(entity);

            entity = new DataEntity();
            entity.FieldName = "StepSeq";
            entity.FieldType = "dataField";
            entity.FieldValue = dr["StepSeq"].ToString();
            inputParaEntity.DataList.Add(entity);

            entity = new DataEntity();
            entity.FieldName = "WorkflowStepID";
            entity.FieldType = "dataField";
            entity.FieldValue = dr["StepID"].ToString();
            inputParaEntity.DataList.Add(entity);

            //yuxj20220830
            if (dr["StepType"].ToString() != "")
            {
                //entity = new DataEntity();
                //entity.FieldName = "SpecType";
                //entity.FieldType = "namedObjectField";
                //entity.FieldValue = ProcessNDOEntity(entity.FieldName, entity.FieldName + "name", dr["StepType"].ToString());
                //inputParaEntity.DataList.Add(entity);

                //update:wangjh 20240711 更改工步类型存储字段
                entity = new DataEntity();
                entity.FieldName = "StepType";
                entity.FieldType = "dataField";
                entity.FieldValue = dr["StepType"].ToString();
                inputParaEntity.DataList.Add(entity);
            }


            #endregion

            return inputParaEntity;
        }
        /// <summary>
        /// 工步关联信息 
        /// </summary>
        /// <param name="dr"></param>
        private void CreateRelationInfo(string stepinfoid, DataRow dr)
        {
            m_DAL.ClearStepInfoTool(stepinfoid);

            int i = 0;
            string SpecialTool = dr["SpecialTool"].ToString();//专用工夹具
            foreach (string strSTool in SpecialTool.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
            {
                string[] strinfo = strSTool.Split('$');
                string toolID = CreateSpecialTool(strinfo);
                if (string.IsNullOrEmpty(toolID))
                    continue;
                i++;
                int qty = 0;
                Int32.TryParse(strinfo[4].Trim(), out qty);
                m_DAL.SaveStepTool(stepinfoid, i, toolID, qty,"1");//yuxj-将本类中的SaveStepTool移到StandardDAL.cs中
            }

            string MeasureTool = dr["MeasureTool"].ToString();//通用工夹具
            foreach (string strMTool in MeasureTool.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
            {
                string[] strinfo = strMTool.Split('$');
                string toolID = CreateMeasureTool(strinfo);
                if (string.IsNullOrEmpty(toolID))
                    continue;
                i++;
                int qty = 0;
                Int32.TryParse(strinfo[6].Trim(), out qty);
                m_DAL.SaveStepTool(stepinfoid, i, toolID, qty, "1");
            }

            // 工序的辅材 统一放到 WorkFlow.cs LoadAuxMaterialProcess方法处理 update:yuxj 20221101
            string AuxMaterial = dr["AuxMaterial"].ToString();//辅料
            WorkFlow wf = new WorkFlow();
            foreach (string strSTool in AuxMaterial.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
            {
                string[] strinfo = strSTool.Split('$');
                string toolID = exectAPI.CreateAuxMaterial(strinfo);
                if (string.IsNullOrEmpty(toolID))
                    continue;
                i++;
                int qty = 0;
                //yuxj20221121辅材数量取值错误，改为strinfo[4]===》strinfo[5]        
                Int32.TryParse(strinfo[5].Trim(), out qty);
                m_DAL.SaveStepTool(stepinfoid, i, toolID, qty,"1");
            }
            /* 工步的检测项统一放到 check.cs处理 update:wangjh 20220831
            string CheckPoint = dr["CheckPoint"].ToString();//检测项
            foreach (string strCPoint in CheckPoint.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
            {
                //"序号$检测项名称$内容$关键过程$工步$质保单$图纸规定$检测项类型" 
                string[] strinfo = strCPoint.Split('$');
                string strWorkflowstepid = dr["StepID"].ToString();
                string strCheckName = strinfo[1].Trim();
                string strCheckNo = strinfo[0].Trim();
                if (m_DAL.IsExistStepCheckPoint2("", strWorkflowstepid, stepinfoid, strCheckName, strCheckNo))
                    continue;
                CreateStepCheckPoint(stepinfoid, strinfo, strWorkflowstepid, strCheckName);
            }
             * */
            string CutTool = dr["CutTool"].ToString();//刀具
            foreach (string strCTool in CutTool.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
            {
                string[] strinfo = strCTool.Split('$');
                string toolID = CreateCutTool(strinfo);
                if (string.IsNullOrEmpty(toolID))
                    continue;
                i++;
                int qty = 0;
                Int32.TryParse(strinfo[6].Trim(), out qty);
                m_DAL.SaveStepTool(stepinfoid, i, toolID, qty, "1");
            }

        }
        //大小件目录
        private void FillBigSmallPart(DataRow dr, DataTable BigSmallPartDT)
        {
            string BigSmallPart = dr["BigSmallPart"].ToString();
            foreach (string strCPoint in BigSmallPart.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
            {
                //"图号$零件名称$初装数量$检装数量$零件类别$备注"
                string[] strinfo = strCPoint.Split('$');
                string strWorkflowstepid = dr["StepID"].ToString();
                string strCheckName = strinfo[1].Trim();
                DataRow bspdr = BigSmallPartDT.NewRow();
                bspdr["StepInfoName"] = dr["StepInfoName"].ToString();
                bspdr["StepInfoRevision"] = dr["Revision"].ToString();
                bspdr["MProductName"] = strinfo[0].Trim();
                bspdr["MProductRevision"] = "";
                bspdr["MProductDesc"] = strinfo[1].Trim();
                bspdr["MSpecName"] = dr["MSpecName"].ToString();
                bspdr["MSpecRevision"] = dr["MSpecRevision"].ToString();
                //Modify by Yuxj20200612 有全角字符及数字转半角,主要是处理用户输入了全角数字导致Bom创建报错的情况
                bspdr["MQtyRequired"] = ToDBC(strinfo[2].Trim());
                bspdr["Qty2"] = ToDBC(strinfo[3].Trim());

                bspdr["BigSmallPart"] = strinfo[4].Trim();
                bspdr["Notes"] = strinfo[5].Trim();
                BigSmallPartDT.Rows.Add(bspdr);
            }
        }
        //Add by Yuxj20200612 全角转半角
        public static string ToDBC(string Input)
        {
            //全角转半角
            char[] c = Input.ToCharArray();
            for (int i = 0; i < c.Length; i++)
            {
                //处理空格
                if (c[i] == 12288)
                {
                    c[i] = (char)32;
                    continue;
                }

                if ((c[i] > 65280) && (c[i] < 65375))
                    c[i] = (char)(c[i] - 65248);
            }
            return new String(c);
        }
        /// <summary>
        /// 创建bom
        /// </summary>
        /// <param name="bomdt"></param>
        /// <param name="IsBigSmallPart">是否大小件</param>
        private void CreateBom(DataTable bomdt, bool IsBigSmallPart)
        {
            if (bomdt.Rows.Count == 0)
                return;
            SyncParameterEntity mainEntity = new SyncParameterEntity();
            List<SyncParameterEntity> productList = new List<SyncParameterEntity>();

            foreach (DataRow dr in bomdt.Rows)
            {
                mainEntity = new SyncParameterEntity();
                string proRev = dr["MProductRevision"].ToString();
                ProductValidate(dr["MProductName"].ToString(), ref  proRev, dr["MProductDesc"].ToString());
                #region 填充bom结构信息
                mainEntity.DataList.Add(new DataEntity("Product", "revisionedObjectField", dr["MProductName"].ToString(), proRev));
                if (!dr.IsNull("MSpecName"))
                {
                    mainEntity.DataList.Add(new DataEntity("Spec", "revisionedObjectField", dr["MSpecName"].ToString(), dr["MSpecRevision"].ToString()));
                }
                mainEntity.DataList.Add(new DataEntity("QtyRequired", "dataField", dr["MQtyRequired"].ToString(), ""));
                mainEntity.DataList.Add(new DataEntity("IssueControl", "dataField", "5", ""));
                mainEntity.DataList.Add(new DataEntity("StepInfo", "revisionedObjectField", dr["StepInfoName"].ToString(), dr["StepInfoRevision"].ToString()));
                if (IsBigSmallPart)
                {
                    mainEntity.DataList.Add(new DataEntity("Qty2Required", "dataField", dr["Qty2"].ToString(), ""));
                    mainEntity.DataList.Add(new DataEntity("Notes", "dataField", dr["Notes"].ToString(), ""));
                    mainEntity.DataList.Add(new DataEntity("BigSmallPart", "dataField", dr["BigSmallPart"].ToString(), ""));
                }
                #endregion
                productList.Add(mainEntity);

            }
            mainEntity = new SyncParameterEntity();
            string strBomName = "";
            if (IsBigSmallPart)
                strBomName = "BSP-" + workFlowProcessno;
            else
                strBomName = "XH-" + workFlowProcessno;
            string strDescription = "";
            #region 填充bom基本信息
            mainEntity.DataList.Add(new DataEntity("Name", "dataField", strBomName, ""));
            mainEntity.DataList.Add(new DataEntity("Revision", "dataField", workFlowRev, ""));
            mainEntity.DataList.Add(new DataEntity("Description", "dataField", strDescription, ""));
            mainEntity.DataList.Add(new DataEntity("Workflow", "revisionedObjectField", "WF-" + workFlowProcessno, workFlowRev));
            mainEntity.DataList.Add(new DataEntity("Product", "revisionedObjectField", ProductName, ProductRevision));
            string strbilltype = "";
            if (IsBigSmallPart)
                strbilltype = ProcessNDOEntity("BillType", "BillTypeName", "大小件目录");
            else
                strbilltype = ProcessNDOEntity("BillType", "BillTypeName", "消耗件");
            mainEntity.DataList.Add(new DataEntity("BillType", "namedObjectField", strbilltype, ""));

            #endregion

            DataTable bomtmpdt = m_DAL.GetRDOByAllVersion("Bom", "BomName", strBomName);
            OutInfoEntity infoEntity = new OutInfoEntity();
            if (bomtmpdt.Rows.Count > 0)
            {
                string strOldVersion = bomtmpdt.Select("BomID=Revofrcdid")[0]["BomRevision"].ToString();
                if (bomtmpdt.Select(string.Format("BomName='{0}' and BomRevision='{1}'", strBomName, workFlowRev)).Length == 0)
                {
                    if (strOldVersion.Trim() == "")
                    {
                        Log.WriteOrcale("PDMTOMES_Bom" + "@^" + strBomName + "未能找到默认版本，无法创建！" + "@^" + m_FileName + "@^" + Convert.ToString(Guid.NewGuid()) + "@^" + ProductName + ":" + ProductRevision);//add:Wangjh 写入数据库          
                        return;
                    }
                    else
                    {
                        exectAPI.CreateWorkflowBomVersion(strBomName, strOldVersion, mainEntity, productList, ref infoEntity);
                    }
                }
                else
                {
                    Log.WriteOrcale("PDMTOMES_Bom" + "@^" + strBomName + "." + workFlowRev + "已经存在！进行更新处理" + "@^" + m_FileName + "@^" + Convert.ToString(Guid.NewGuid()) + "@^" + ProductName + ":" + ProductRevision);//add:Wangjh 写入数据库          
                    exectAPI.UpdateRDOEntity("WorkflowBOM", strBomName, strOldVersion, mainEntity, ref infoEntity);
                }
            }
            else
            {
                exectAPI.CreateWorkflowBom(mainEntity, productList, ref infoEntity);
            }
            OutParameterObjectList.Add(infoEntity);
            if (infoEntity.OutFlag == 1)//add:Wangjh 2017-9-15
            {
                Log.WriteOrcale("PDMTOMES_" + infoEntity.StrServicekey + "@^" + strBomName + "Bom创建成功" + "@^" + m_FileName + "@^" + Convert.ToString(Guid.NewGuid()) + "@^" + ProductName + ":" + ProductRevision);//add:Wangjh 写入数据库          
            }
            else if (infoEntity.OutFlag == 2)
            {
                Log.WriteOrcale("PDMTOMES_" + infoEntity.StrServicekey + "@^" + "Bom创建失败:" + infoEntity.StrInfo + "@^" + m_FileName + "@^" + Convert.ToString(Guid.NewGuid()) + "@^" + ProductName + ":" + ProductRevision);//add:Wangjh 写入数据库          
            }
        }

        
        /// <summary>
        /// 创建检测项
        /// </summary>
        /// <param name="stepinfoid"></param>
        /// <param name="strinfo"></param>
        /// <param name="strWorkflowstepid"></param>
        /// <param name="strCheckName"></param>
        private void CreateStepCheckPoint(string stepinfoid, string[] strinfo, string strWorkflowstepid, string strCheckName)
        {
            string CheckType = "1";
            string CheckInputType = "1";
            string intNum = "1";
            string CheckPointNote = "";
            string TCCheckPointNote = strinfo[2].Trim();
            try
            {
                CheckPointNote = m_Assistant.CheckDraw(TCCheckPointNote);
            }
            catch (Exception e)
            {
            }
            if (CheckPointNote == string.Empty)
            {
                CheckPointNote = TCCheckPointNote;
            }
            try
            {
                int.Parse(strinfo[0].Trim());
            }
            catch (Exception e)
            {
                Log.WriteOrcale("PDMTOMES_CHECK" + "@^" + strinfo[0].Trim() + " 检测项序号格式不正确，无法创建！" + "@^" + m_FileName + "@^" + Convert.ToString(Guid.NewGuid()) + "@^" + ProductName + ":" + ProductRevision);//add:Wangjh 写入数据库                 
                return;
            }
            SortedList<string, object> list = new SortedList<string, object>();
            list.Add("CheckInputType", CheckInputType);
            list.Add("CheckNO", strinfo[0].Trim());
            list.Add("CheckPointNote", CheckPointNote);
            list.Add("CheckType", CheckType);
            list.Add("IntNum", intNum);
            if (strinfo[3].Trim() == "true")
                list.Add("KeyCheck", "1");
            else
                list.Add("KeyCheck", "0");
            if (strinfo[4].Trim() == "true")
                list.Add("MeopCheck", "1");
            else
                list.Add("MeopCheck", "0");
            if (strinfo[5].Trim() == "true")
                list.Add("QualityCheck", "1");
            else
                list.Add("QualityCheck", "0");
            list.Add("CheckName", strCheckName);
            list.Add("Productid", "");
            list.Add("Workflowstepid", strWorkflowstepid);
            list.Add("TCCheckPointNote", TCCheckPointNote);
            list.Add("StepInfoID", stepinfoid);
            //add:Wangjh 20180508 增加判断
            if (strinfo.Length > 6)
            { list.Add("DrawingRequire", strinfo[6].Trim()); }
            else
            { list.Add("DrawingRequire", ""); }
            if (strinfo.Length > 7)
            { list.Add("AssemblyType", strinfo[7].Trim()); }
            else
            { list.Add("AssemblyType", ""); }
            //

            m_DAL.InsertIntoStepCheckPointTable(list);

        }
        /// <summary>
        /// 创建专用工夹具
        /// </summary>
        /// <param name="strinfo"></param>
        /// <returns></returns>
        private string CreateSpecialTool(string[] strinfo)
        {
            // "工装编码$图号$名称$规格$数量$备注"
            string toolID = "";
            string cdoName = "SpecialTool";
            string cdoFieldName = "SpecialToolName";
            string cdoFieldID = "SpecialToolID";
            string name = strinfo[0].Trim();
            SyncParameterEntity inputParaEntity = new SyncParameterEntity();
            DataSet ds = m_DAL.GetNDOTable(cdoName, cdoFieldName, name);
            if (ds.Tables[0].Rows.Count > 0)
            {
                toolID = ds.Tables[0].Rows[0][cdoFieldID].ToString();
            }
            else
            {
                #region 属性赋值

                inputParaEntity.DataList.Add(new DataEntity("Name", "dataField", name, ""));
                inputParaEntity.DataList.Add(new DataEntity("DrawingNo", "dataField", strinfo[1].Trim(), ""));
                inputParaEntity.DataList.Add(new DataEntity("Description", "dataField", strinfo[2].Trim(), ""));
                inputParaEntity.DataList.Add(new DataEntity("Notes", "dataField", strinfo[5].Trim(), ""));
                #endregion

                DataEntity entity = new DataEntity();
                entity.FieldName = "ResourceType";
                entity.FieldType = "namedObjectField";
                if (string.IsNullOrEmpty(strinfo[1].Trim()))
                {
                    entity.FieldValue = "通用";
                }
                else
                {
                    entity.FieldValue = "专用";
                }

                inputParaEntity.DataList.Add(entity);

                OutInfoEntity infoEntity = new OutInfoEntity();
                ExecuteAPI exectAPI = new ExecuteAPI();
                exectAPI.CreateNDOEntity(cdoName, inputParaEntity, ref infoEntity);
                m_OutParameterObjectList.Add(infoEntity);
                if (infoEntity.OutFlag == 1)
                {
                    ds = m_DAL.GetNDOTable(cdoName, cdoFieldName, name);
                    toolID = ds.Tables[0].Rows[0][cdoFieldID].ToString();
                }
            }
            return toolID;
        }
        /// <summary>
        /// 创建标准工夹具
        /// </summary>
        /// <param name="strinfo"></param>
        /// <returns></returns>
        private string CreateMeasureTool(string[] strinfo)
        {
            //"工装编码$名称$规格$量程$精度$标准号$数量$备注"
            string toolID = "";
            string cdoName = "MeasureTool";
            string cdoFieldName = "MeasureToolName";
            string cdoFieldID = "MeasureToolID";
            string name = strinfo[0].Trim();
            SyncParameterEntity inputParaEntity = new SyncParameterEntity();
            DataSet ds = m_DAL.GetNDOTable(cdoName, cdoFieldName, name);
            if (ds.Tables[0].Rows.Count > 0)
            {
                toolID = ds.Tables[0].Rows[0][cdoFieldID].ToString();

            }
            else
            {
                #region 属性赋值
                inputParaEntity.DataList.Add(new DataEntity("Name", "dataField", name, ""));
                inputParaEntity.DataList.Add(new DataEntity("Description", "dataField", strinfo[1].Trim(), ""));
                inputParaEntity.DataList.Add(new DataEntity("Specification", "dataField", strinfo[2].Trim(), ""));
                inputParaEntity.DataList.Add(new DataEntity("VendorSerialNumber", "dataField", strinfo[5].Trim(), ""));
                inputParaEntity.DataList.Add(new DataEntity("MeasureRange", "dataField", strinfo[3].Trim(), ""));
                inputParaEntity.DataList.Add(new DataEntity("MeasurePrecision", "dataField", strinfo[4].Trim(), ""));
                inputParaEntity.DataList.Add(new DataEntity("Notes", "dataField", strinfo[7].Trim(), ""));
                #endregion

                OutInfoEntity infoEntity = new OutInfoEntity();
                ExecuteAPI exectAPI = new ExecuteAPI();
                exectAPI.CreateNDOEntity(cdoName, inputParaEntity, ref infoEntity);
                m_OutParameterObjectList.Add(infoEntity);
                if (infoEntity.OutFlag == 1)
                {
                    ds = m_DAL.GetNDOTable(cdoName, cdoFieldName, name);
                    toolID = ds.Tables[0].Rows[0][cdoFieldID].ToString();
                }
            }
            return toolID;
        }
        /// <summary>
        /// 创建标准刀具 add by longb 2023-08-14
        /// </summary>
        /// <param name="strinfo"></param>
        /// <returns></returns>
        private string CreateCutTool(string[] strinfo)
        {
            //创建标准刀具
            string toolID = "";
            string cdoName = "CutTool";
            string cdoFieldName = "CutToolName";
            string cdoFieldID = "CutToolID";
            string name = strinfo[0].Trim();
            SyncParameterEntity inputParaEntity = new SyncParameterEntity();
            DataSet ds = m_DAL.GetNDOTable(cdoName, cdoFieldName, name);
            if (ds.Tables[0].Rows.Count > 0)
            {
                toolID = ds.Tables[0].Rows[0][cdoFieldID].ToString();

            }
            else
            {
                #region 属性赋值
                inputParaEntity.DataList.Add(new DataEntity("Name", "dataField", name, ""));//刀具编码
                inputParaEntity.DataList.Add(new DataEntity("Description", "dataField", strinfo[1].Trim(), ""));//刀具名称
                inputParaEntity.DataList.Add(new DataEntity("Specification", "dataField", strinfo[2].Trim(), ""));//规格
                inputParaEntity.DataList.Add(new DataEntity("VendorSerialNumber", "dataField", strinfo[5].Trim(), ""));//标准号
                inputParaEntity.DataList.Add(new DataEntity("DrawingNo", "dataField", strinfo[3].Trim(), ""));//图号
                inputParaEntity.DataList.Add(new DataEntity("Notes", "dataField", strinfo[4].Trim(), ""));//备注
                #endregion

                OutInfoEntity infoEntity = new OutInfoEntity();
                ExecuteAPI exectAPI = new ExecuteAPI();
                exectAPI.CreateNDOEntity(cdoName, inputParaEntity, ref infoEntity);
                m_OutParameterObjectList.Add(infoEntity);
                if (infoEntity.OutFlag == 1)
                {
                    ds = m_DAL.GetNDOTable(cdoName, cdoFieldName, name);
                    toolID = ds.Tables[0].Rows[0][cdoFieldID].ToString();
                }
            }
            return toolID;
        }
        


        private string ProcessNDOEntity(string strTable, string strName, string strValue)
        {
            DataSet ds = m_DAL.GetNDOTable(strTable, strName, strValue);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return strValue;
            }
            else
            {
                OutInfoEntity infoEntity = new OutInfoEntity();
                SyncParameterEntity tmpEntity = new SyncParameterEntity();
                DataEntity entity = new DataEntity();
                entity.FieldName = "Name";
                entity.FieldType = "dataField";
                entity.FieldValue = strValue;
                tmpEntity.DataList.Add(entity);

                exectAPI.CreateNDOEntity(strTable, tmpEntity, ref infoEntity);
                m_OutParameterObjectList.Add(infoEntity);
                if (infoEntity.OutFlag == 2)//add:Wangjh 2017-9-15 
                {
                    Log.WriteOrcale("PDMTOMES_" + infoEntity.StrServicekey + "@^" + strTable + "创建失败:" + infoEntity.StrInfo + "@^" + m_FileName + "@^" + Convert.ToString(Guid.NewGuid()) + "@^" + ProductName + ":" + ProductRevision);//add:Wangjh 写入数据库   

                }
                else
                {
                    Log.WriteOrcale("PDMTOMES_" + infoEntity.StrServicekey + "@^" + strTable + "创建成功" + "@^" + m_FileName + "@^" + Convert.ToString(Guid.NewGuid()) + "@^" + ProductName + ":" + ProductRevision);//add:Wangjh 写入数据库   
                    return strValue;
                }
            }
            return string.Empty;
        }


        private void ProductValidate(string strTmpProuctName, ref string strTmpVersion, string description)
        {
            OutInfoEntity infoEntity = new OutInfoEntity();
            SyncParameterEntity productEntity = new SyncParameterEntity();
            productEntity.DataList = new List<DataEntity>();
            DataEntity myEntity = new DataEntity();
            myEntity.FieldName = "Name";
            myEntity.FieldType = "dataField";
            myEntity.FieldValue = strTmpProuctName;
            productEntity.DataList.Add(myEntity);

            myEntity = new DataEntity();
            myEntity.FieldName = "Revision";
            myEntity.FieldType = "dataField";
            if (string.IsNullOrWhiteSpace(strTmpVersion))//没有版本默认00
                myEntity.FieldValue = "00";
            else
                myEntity.FieldValue = strTmpVersion;
            productEntity.DataList.Add(myEntity);

            myEntity = new DataEntity();
            myEntity.FieldName = "Description";
            myEntity.FieldType = "dataField";
            myEntity.FieldValue = description;
            productEntity.DataList.Add(myEntity);

            myEntity = new DataEntity();
            myEntity.FieldName = "ProductType";
            myEntity.FieldType = "namedObjectField";
            myEntity.FieldValue = "零件";
            productEntity.DataList.Add(myEntity);

            DataTable productdt = m_DAL.GetRDOByAllVersion("Product", "ProductName", strTmpProuctName);

            if (productdt.Rows.Count > 0)
            {
                if (productdt.Select(string.Format("ProductName='{0}' and ProductRevision='{1}'", strTmpProuctName, strTmpVersion)).Length == 0)
                {
                    string strVer = productdt.Select("ProductID=Revofrcdid")[0]["ProductRevision"].ToString();
                    if (string.IsNullOrWhiteSpace(strTmpVersion))//没有版本，取默认版本
                    {
                        strTmpVersion = strVer;
                        return;
                    }else
                    exectAPI.CreateRDOEntityRevision("Product", strTmpProuctName, strVer, productEntity, ref infoEntity);
                }
            }
            else  //没有零件图号
            {

                exectAPI.CreateRDOEntity("Product", productEntity, ref infoEntity);
            }
            if (infoEntity.OutFlag == 1)//add:Wangjh 2017-9-26
            {
                Log.WriteOrcale("PDMTOMES_" + infoEntity.StrServicekey + "@^" + strTmpProuctName + "Product创建成功" + "@^" + m_FileName + "@^" + Convert.ToString(Guid.NewGuid()) + "@^" + ProductName + ":" + ProductRevision);//add:Wangjh 写入数据库          
            }
            else if (infoEntity.OutFlag == 2)
            {
                Log.WriteOrcale("PDMTOMES_" + infoEntity.StrServicekey + "@^" + "Product创建失败:" + infoEntity.StrInfo + "@^" + m_FileName + "@^" + Convert.ToString(Guid.NewGuid()) + "@^" + ProductName + ":" + ProductRevision);//add:Wangjh 写入数据库          
            }
        }

        /// <summary>
        /// 填充urls信息
        /// add:Wangjh 20181114
        /// </summary>
        /// <param name="urlDt"></param>
        /// <param name="urls"></param>
        private void LoadUrlsInfo(DataTable stepinfo)
        {
            //获取到装试工序节点
            XmlDocument myxml = new XmlDocument();
            myxml.Load(m_DataFilePath);
            XmlNodeList ZSStep = myxml.SelectNodes("/Root/WorkFlow/MEOPs/MEOP/STEPs/STEP");
            if (ZSStep.Count == 0)
                return;
            m_DAL =new StandardDAL();
            //
            foreach (XmlNode stepNode in ZSStep) 
            {
                XmlNodeList urlNodes = stepNode.SelectNodes("Urls/Url");
                if (urlNodes.Count == 0)
                    continue;
                DataRow[] drs = stepinfo.Select("StepNo='" + stepNode.SelectSingleNode("ly2meop_no").InnerText + "' and Description='" + stepNode.SelectSingleNode("object_name").InnerText + "'");
                if (drs.Length == 0)
                    continue;
                string parentID = m_DAL.GetStepInfoIDByStepNameAndRev(drs[0]["StepInfoName"].ToString(), drs[0]["Revision"].ToString());
                if (parentID == "")
                    continue;
                Dictionary<string, string> para = new Dictionary<string, string>();
                para["ParentID"] = parentID;
                foreach (XmlNode url in urlNodes)
                {
                    string name = "", link = "";
                    foreach (XmlNode urlItem in url.ChildNodes)
                    {
                        if (urlItem.Name == "name")
                            name = urlItem.InnerText;
                        if (urlItem.Name == "link")
                            link = urlItem.InnerText;
                        if (name != "" && link != "")
                        {
                            para["FileName"] = name;
                            para["Link"] = link;
                            m_DAL.InsertUrl(para);
                        }
                    }
                }
            }
        }        

        /// <summary>
        /// 继承上个版本的工步部分信息
        /// add:wangjh 20240910
        /// </summary>
        /// <param name="infoEntity"></param>
        /// <param name="workFlowName"></param>
        private void inheritLastWorkflowSomeInfo(string workFlowName, string curWorkFlowRev)
        {
            string strfactory = m_DAL.GetFacorybyCode(m_ProcessPlant);
            DataTable workflowDt = m_DAL.GetAllWorkflow(strfactory, workFlowName);
            if (workflowDt.Rows[0]["workflowrevision"].ToString() != curWorkFlowRev)
            {
                return;
            }
            if (workflowDt.Rows.Count > 1)//至少2个版本包括当前版本
            {
                string lastWorkflowId = workflowDt.Rows[1]["workflowid"].ToString();//上一个版本的工艺ID
                DataTable lastStepInfoDt = m_DAL.GetStepInfoByWorkflowId(lastWorkflowId);
                //DataTable origLastStepDt = lastStepInfoDt.Copy();//复制一份，防止更新工区班组时值变化
                string newWorkflowID = workflowDt.Rows[0]["workflowid"].ToString();//刚添加最新版本的
                DataTable newStepInfoDt = m_DAL.GetStepInfoByWorkflowId(newWorkflowID);//最新版本的工序信息
                //添加上一个版本的期量数据 add:Wangjh 20180201                              
                DataRow[] HaveStepTimeDrs = lastStepInfoDt.Select(@"makecycle is not null OR preparecycle IS NOT NULL OR shipcycle IS NOT NULL OR steptype IS NOT NULL 
                or transfercycle is not null or chargingqty is not null");
                //上一个版本工步的
                if (HaveStepTimeDrs.Length > 0)//上一个版本有工时或有工区或有班组
                {
                    foreach (DataRow dr in HaveStepTimeDrs)
                    {
                        DataRow[] temDrs = newStepInfoDt.Select(string.Format(" WORKFLOWSTEPNAME='{0}' AND stepseq={1} and stepinfodesc='{2}' ", dr["WORKFLOWSTEPNAME"].ToString(), dr["stepseq"].ToString(), dr["stepinfodesc"].ToString()));
                        if (temDrs.Length == 0)
                            continue;
                        foreach (DataRow tempDr in temDrs)
                        {
                            dr["stepinfoid"] = tempDr["stepinfoid"].ToString();
                            m_DAL.UpdateStepInfoTime(dr);
                            Log.WriteOrcale("PDMTOMES_StepInfo" + "@^" + "最新版" + workFlowName + ":" + curWorkFlowRev + " 工序" + dr["WORKFLOWSTEPNAME"].ToString() + "，工步" + dr["stepinfoid"].ToString() + "期量信息继承成功" + "@^" + m_FileName + "@^" + Convert.ToString(Guid.NewGuid()) + "@^" + ProductName + ":" + ProductRevision);//add:Wangjh 写入数据库 

                        }

                    }
                }

                //添加上一个版本的工步设备数据 add:Wangjh 20241113
                DataTable stepInfoResDt = m_DAL.GetStepInfoResource(lastWorkflowId);
                if (stepInfoResDt.Rows.Count > 0)
                {
                    ArrayList sqlList = new ArrayList();
                    foreach (DataRow stepInfoResDr in stepInfoResDt.Rows)
                    {
                        DataRow[] temDrs = newStepInfoDt.Select(string.Format(" WORKFLOWSTEPNAME='{0}' AND stepseq={1} and stepinfodesc='{2}' ", stepInfoResDr["WORKFLOWSTEPNAME"].ToString(), stepInfoResDr["stepseq"].ToString(), stepInfoResDr["stepinfodesc"].ToString()));
                        if (temDrs.Length == 0)
                            continue;
                        foreach (DataRow tempDr in temDrs)
                        {
                            sqlList.Add(string.Format("INSERT INTO stepresourceinfo (stepid,resourceid,stepresourceinfoid) VALUES ('{0}','{1}',sys_guid())",
                                tempDr["stepinfoid"].ToString(), stepInfoResDr["resourceid"].ToString()));
                        }

                    }
                    m_DAL.ExecuteSqlTran(sqlList);

                }
            }
        }
    }
}
